package com.xmu.prcs.service.impl;

import java.util.List;

import com.xmu.prcs.dao.UserDao;
import com.xmu.prcs.entity.User;
import com.xmu.prcs.service.SystemManager;
import com.xmu.prcs.util.DictionaryUtil;
import com.xmu.prcs.util.EncryptHelper;

public class SystemManagerImpl implements SystemManager {

	private UserDao userDao;
	
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}


	public int loginToSystem(String name, String password) {
		List<User> list = userDao.findByProperty(UserDao.USER_NAME, name);
		if(list == null || list.size() == 0){
			System.out.println("11111111");
			return DictionaryUtil.LOGIN_NO_NAME;
		}
		User user = list.get(0);
		if(user == null){
			System.out.println("2222222222");
			return DictionaryUtil.LOGIN_NO_NAME;
		}
		EncryptHelper encrypt = EncryptHelper.getInstance();
		if(!encrypt.compareString(user.getPassword(), encrypt.encryptString(password))){
			System.out.println("3333333333");
			return DictionaryUtil.LOGIN_WRONG_PASSWORD;
		}
		System.out.println("444444444444");
		return DictionaryUtil.LOGIN_SUCCESS;
	}
}
